package com.sharp.authorization.controller.admin;

import com.sharp.authorization.annotation.auth.AdminAuthRole;
import com.sharp.authorization.annotation.auth.Auth;
import com.sharp.authorization.service.login.LoginService;
import com.sharp.authorization.vo.login.LoginRes;
import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.kernel.vo.common.CommonResVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * Title: AdminController
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/3/29 17:28
 */
@ApiIgnore
@Auth(AdminAuthRole.class)
@Api(value = "后台管理员", tags = "后台管理员")
@RestController("AdminController")
@RequestMapping(value = "/admin")
public class AdminController {

    @Resource
    private LoginService loginService;

    @ApiOperation(value = "超管用户登入", notes = "利用他人账号登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "loginId", value = "用户名", required =
                    true)})
    public ResponseEntity<Response<LoginRes>> ghostLogin(String loginId) {
        LoginRes res = loginService.ghostLogin(loginId);
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "改变账户状态", notes = "改变账户状态")
    @RequestMapping(value = "/account/status", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "userId", value = "用户id", required =
                    true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "status", value = "用户状态", required =
                    true),})
    public ResponseEntity<Response<CommonResVO>> changeAccountStatus(String userId, String status) {
        loginService.changeAccountStatus(userId, status);
        return ResponseHandler.commonResponse();
    }


}
